package com.lagou.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * json工具类
 */
public class JsonUtil {
	private static final ObjectMapper MAPPER = new ObjectMapper();
	//将对象转为json
	public static String object2Json(Object o) throws JsonProcessingException {
		String mapJson = MAPPER.writeValueAsString(o);
		return mapJson;
	}
	// 将json转为对象
	public static <T> T json2Object(String jsonData, Class<T> beanType) throws IOException {
			T t = MAPPER.readValue(jsonData, beanType);
			return t;
	}

}
